/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2023-11-13 17:00:38
 * @LastEditors: htang
 * @LastEditTime: 2023-11-13 19:29:29
 */
import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

const API = {
  // 摄像头列表分页
  page: '/camera/page',
  // 摄像头列表
  list: '/camera/list',
  // 摄像头删除
  delete: '/camera/delete',
  // 摄像头详情
  info: '/camera/info',
  // 新增摄像头信息
  add: '/camera/insert',
  // 修改摄像头信息
  modify: '/camera/modify'
}

/**
 * 获取摄像头分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const cameraPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
}

/**
 * 根据ID获取摄像头详情
 * @returns
 */
export const cameraInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 获取摄像头列表
 * @returns
 */
export const cameraListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}

/**
 * 摄像头编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E6%91%84%E5%83%8F%E5%A4%B4/infoUsingGET_1}
 * @param {String} IP IP地址
 * @param {String} name 摄像头名称
 * @param {String} password 摄像头密码
 * @param {String} username 用户名
 * @param {String} port 端口
 * @param {String} stationCode 站点编码
 * @returns
 */
export const cameraAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.add, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 摄像头编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E6%91%84%E5%83%8F%E5%A4%B4/infoUsingGET_1}
 * @param {String} IP IP地址
 * @param {String} name 摄像头名称
 * @param {String} password 摄像头密码
 * @param {String} username 用户名
 * @param {String} port 端口
 * @param {String} stationCode 站点编码
 * @returns
 */
export const cameraModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除摄像头接口
 * @param {*} id
 * @returns
 */
export const cameraDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前摄像头数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}